package com.zzx.handler;

import com.alibaba.fastjson.JSON;
import com.zzx.exception.ExceptionState;
import com.zzx.util.ResponseResult;
import com.zzx.util.ResponseWrite;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*授权异常类*/
@Component
public class AccessDeniedException  implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, org.springframework.security.access.AccessDeniedException accessDeniedException) throws IOException, ServletException {
        ResponseResult<String> stringResponseResult = new ResponseResult(ExceptionState.FORBIDDEN);
        String s = JSON.toJSONString(stringResponseResult);
        ResponseWrite.ResponseString(response,s);
    }
}
